﻿using Microsoft.Extensions.Configuration;
using ProxyServer.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;

namespace ProxyServer.CommandLine
{
    public class DesignTimeFactoryBuilder
    {
        public static AbstractDesignTimeFactory Build(string[] args)
        {
            var configuration = AbstractDesignTimeFactory.BuildBaseConfiguration(args).Build();
            var databaseProvider = configuration.GetDatabaseProvider();

            return Build(databaseProvider, configuration);
        }

        public static AbstractDesignTimeFactory Build(string? providerName, IConfiguration configuration)
        {
            return providerName switch
            {
                DatabaseProviderNames.Npgsql => new NpgsqlDesignTimeFactory(configuration),
                DatabaseProviderNames.Sqlite => new SqliteDesignTimeFactory(configuration),
                _ => throw new ArgumentException($"Unsupported database provider name: {providerName}")
            };
        }
    }
}
